<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
	<body>
		
		<div id="permissionToolbar">
			<div class="permissionToolbar_button" style="height: 40px;">
	            <a href="#" class="easyui-linkbutton" iconCls="icon-edit" onclick="permission_openEdit()" plain="true">修改</a>
	            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" onclick="permission_remove()" plain="true">删除</a>
	            <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="permission_cancel()" plain="true">取消</a>
	            <a href="#" class="easyui-linkbutton" iconCls="icon-reload" onclick="permission_reload()" plain="true">刷新</a>
			</div>
		</div>
		
		<table id="permission_dg"></table>
		
		<script type="text/javascript">
			$(function(){
				$('#permission_dg').datagrid({
					url:pageContext_request_contextPath+'permissions',
					method:"get",
					//toolbar:"#permissionToolbar",
					pagination:true,
					fitColumns:true,
					border:false,
					pageSize:10,
					columns:[[
						{field:"ck",checkbox:true},
						{field:'id',title:'power_code',width:100},
						{field:'resource',title:'resource',width:100},
						{field:"state",title:"state",width:200,formatter:function(value,row,index){
							if(value == 1){
								return "正常状态";
							}else{
								return "禁用状态";
							}
						}}
					]]
				});

			})
			

			
			function permission_openEdit() {
				var rows = $("#permission_dg").datagrid("getSelections");

				if(rows.length == 0){
					$.messager.alert("信息提示","请勾选您要修改的数据！","info");
				}else{
					$.messager.confirm("信息提示", "确定要禁用选中的权限吗？", function(result) {
						if (result) {
							var ids = [];
							$(rows).each(function() {
								ids.push(this.id);
							});
							$.ajax({
								url: "/filesharingsystem/permissions",
								method: "put",
								contentType: "application/json;charset=utf-8",
								data: JSON.stringify(ids),
								success: function(data) { //"ok","error"
									if (data == "ok") {
										permission_reload();
									} else {
										$.messager.alert("信息提示", "修改失败！", "info");
									}
								}
							});
						}
					});				
				}
			}
			
			
			function permission_remove() {
				var rows = $("#permission_dg").datagrid("getSelections");
				if(rows.length < 1){
					$.messager.alert("信息提示","请勾选您要删除的数据！","info");
				}else{
					$.messager.confirm("信息提示","确定要删除选中的记录吗？",function(result){
						if(result){
							var ids = [];
							$(rows).each(function(){
								ids.push(this.id);
							});
							$.ajax({
								url:"/filesharingsystem/permissions",
								contentType: "application/json;charset=utf-8",
								method: "delete",
								data: JSON.stringify(ids),
								success:function(data){ //"ok","error"
									permission_reload();},
								error:function(){
									$.messager.alert("信息提示","删除失败！","info");
								}
							});
						}
					});
				}
			}

			function permission_add() {
				//alert($(#permissionsId).value);
				doAjax("/filesharingsystem/permission","post");
			}
			
			function doAjax(param,_method){
				$.ajax({
					url:param,
					method:_method,
					contentType:"application/json;charset=utf-8",
					data:JSON.stringify({
						id:$("#id").val(),
						resource:$("#resource").val(),
						state:$("#state").val(),
					}),
					success:function(data){ //"ok","error"
						$("#permission_dialog").dialog("close");
						permission_reload();							
					},
					error:function(){
						$.messager.alert("信息提示","提交失败！","info");
					}
				});
			}
			
			function permission_cancel() {
				$("#permission_dg").datagrid("rejectChanges");
			}
			
			function permission_reload() {
				$("#permission_dg").datagrid("reload");
			}
		</script>
		
	</body>
</html>



